# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=webkitgtk

pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}2" "${MINGW_PACKAGE_PREFIX}-${_realname}3")
pkgver=2.2.6
pkgrel=2
pkgdesc="GTK+ Web content engine library (mingw-w64)"
arch=('any')
url="http://webkitgtk.org/"
license=("custom")
options=('!libtool' 'strip' '!debug' 'staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
    "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
    "${MINGW_PACKAGE_PREFIX}-pkg-config"
    "${MINGW_PACKAGE_PREFIX}-gtk2"
    "${MINGW_PACKAGE_PREFIX}-gtk3"
    "bison"
    "flex"
    "gperf"
    "libtool"
    "gtk-doc"
    "perl"
    "${MINGW_PACKAGE_PREFIX}-python2"
    "${MINGW_PACKAGE_PREFIX}-ruby"
    )
depends=(
    "${MINGW_PACKAGE_PREFIX}-angleproject"
    "${MINGW_PACKAGE_PREFIX}-cairo"
    "${MINGW_PACKAGE_PREFIX}-enchant"
    "${MINGW_PACKAGE_PREFIX}-fontconfig"
    "${MINGW_PACKAGE_PREFIX}-freetype"
    "${MINGW_PACKAGE_PREFIX}-glib2"
    "${MINGW_PACKAGE_PREFIX}-gst-plugins-base"
    "${MINGW_PACKAGE_PREFIX}-gstreamer"
    "${MINGW_PACKAGE_PREFIX}-geoclue"
    "${MINGW_PACKAGE_PREFIX}-harfbuzz"
    "${MINGW_PACKAGE_PREFIX}-icu"
    "${MINGW_PACKAGE_PREFIX}-libidn"
    "${MINGW_PACKAGE_PREFIX}-libjpeg"
    "${MINGW_PACKAGE_PREFIX}-libpng"
    "${MINGW_PACKAGE_PREFIX}-libsoup"
    "${MINGW_PACKAGE_PREFIX}-sqlite3"
    "${MINGW_PACKAGE_PREFIX}-libxml2"
    "${MINGW_PACKAGE_PREFIX}-libxslt"
    "${MINGW_PACKAGE_PREFIX}-libwebp"
    "${MINGW_PACKAGE_PREFIX}-pango"
    "${MINGW_PACKAGE_PREFIX}-xz"
    )
source=(http://webkitgtk.org/releases/webkitgtk-${pkgver}.tar.xz
    0001-webkitgtk-remove-reference-to-nonexisting-header.mingw.patch
    0002-webkitgtk-mingw-use-gcc-asm.mingw.patch
    0003-webkit-dont-build-dump-render-tree.mingw.patch
    0004-webkitgtk-mingw-dont-declare-readwritebarrier.mingw.patch
    0005-webkitgtk-mingw-compile-fix.mingw.patch
    0006-webkitgtk-mingw-prevent-no-error-name-conflict.mingw.patch
    0007-webkitgtk-mingw-fix-includes.mingw.patch
    0008-webkit-fix-angle-windows-compilation.mingw.patch
    0009-webkitgtk-mingw-m-pi.mingw.patch
    0010-webkitgtk-prevent-multiple-plugins-definitions.mingw.patch
    0011-webkitgtk-mingw-opengl.mingw.patch
    0012-webkitgtk-dont-build-test-webkit-api.mingw.patch
    0013-webkitgtk-redo-commit-148663.mingw.patch
    0014-webkitgtk-workaround-conflicting-htonl-on-win64.mingw.patch
    0015-use-gstatbuf.all.patch
    0016-non-volatile-refc-in-audio.mingw.patch
    0017-make-sure-correct-gcc-is-used.mingw.patch
    0018-use-la-libs-for-g-i.all.patch
    0021-use-configured-python-for-this.all.patch
    0023-use-path-instead-of-ld-library-path-on.mingw.patch
    0024-use-stabs-to-get-smaller-debug-builds.mingw.patch
    0025-webkitgtk-2.2.5-icu-libraries.patch
    0026-webkitgtk-mingw-gnu-print.patch
    0027-webkitgtk-windows-fix-egl.patch
    0028-Use-after-free-in-WTF-threading-code.patch
    0029-pass-python-and-cflags-to-girscanner.patch)

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-webkitgtk-remove-reference-to-nonexisting-header.mingw.patch
  patch -p1 -i ${srcdir}/0002-webkitgtk-mingw-use-gcc-asm.mingw.patch
  patch -p1 -i ${srcdir}/0003-webkit-dont-build-dump-render-tree.mingw.patch
  patch -p1 -i ${srcdir}/0004-webkitgtk-mingw-dont-declare-readwritebarrier.mingw.patch
  patch -p1 -i ${srcdir}/0005-webkitgtk-mingw-compile-fix.mingw.patch
  patch -p1 -i ${srcdir}/0006-webkitgtk-mingw-prevent-no-error-name-conflict.mingw.patch
  patch -p1 -i ${srcdir}/0007-webkitgtk-mingw-fix-includes.mingw.patch
  patch -p1 -i ${srcdir}/0008-webkit-fix-angle-windows-compilation.mingw.patch
  patch -p1 -i ${srcdir}/0009-webkitgtk-mingw-m-pi.mingw.patch
  patch -p1 -i ${srcdir}/0010-webkitgtk-prevent-multiple-plugins-definitions.mingw.patch
  patch -p1 -i ${srcdir}/0011-webkitgtk-mingw-opengl.mingw.patch
  patch -p1 -i ${srcdir}/0012-webkitgtk-dont-build-test-webkit-api.mingw.patch
  patch -p1 -i ${srcdir}/0013-webkitgtk-redo-commit-148663.mingw.patch
  patch -p1 -i ${srcdir}/0014-webkitgtk-workaround-conflicting-htonl-on-win64.mingw.patch
  patch -p1 -i ${srcdir}/0015-use-gstatbuf.all.patch
  patch -p1 -i ${srcdir}/0016-non-volatile-refc-in-audio.mingw.patch
  patch -p1 -i ${srcdir}/0017-make-sure-correct-gcc-is-used.mingw.patch
  patch -p1 -i ${srcdir}/0018-use-la-libs-for-g-i.all.patch
  patch -p1 -i ${srcdir}/0021-use-configured-python-for-this.all.patch
  patch -p1 -i ${srcdir}/0023-use-path-instead-of-ld-library-path-on.mingw.patch
  patch -p1 -i ${srcdir}/0024-use-stabs-to-get-smaller-debug-builds.mingw.patch
  patch -p1 -i ${srcdir}/0025-webkitgtk-2.2.5-icu-libraries.patch
  patch -p1 -i ${srcdir}/0026-webkitgtk-mingw-gnu-print.patch
  patch -p1 -i ${srcdir}/0027-webkitgtk-windows-fix-egl.patch
  patch -p1 -i ${srcdir}/0028-Use-after-free-in-WTF-threading-code.patch
  patch -p1 -i ${srcdir}/0029-pass-python-and-cflags-to-girscanner.patch

  autoreconf --verbose --install -I Source/autotools
  
  rm -rf ${srcdir}/build-gtk{2,3}
  mkdir -p ${srcdir}/build-gtk{2,3}
}

_build() {
  _ver="$1"; shift
  cd ${srcdir}/build-${_ver}

  export PYTHON=${MINGW_PREFIX}/bin/python2
  export RUBY=${MINGW_PREFIX}/bin/ruby

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --disable-debug \
    --enable-debug-symbols \
    --enable-introspection \
    --disable-credential-storage \
    --disable-accelerated-compositing \
    --enable-jit \
    --disable-webkit2 \
    --disable-glibtest \
    --disable-static \
    --enable-shared \
    --enable-video \
    --enable-spellcheck \
    --enable-optimizations \
    --enable-geolocation \
    --with-target=win32 \
    --enable-gles2=no \
    --enable-egl=no \
    "$@"

  PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${srcdir}/build-${_ver}/SourceJavaScriptCore \
    make V=1 all stamp-po
}

build() {
  _build gtk3 --disable-gtk-doc --disable-webkit2 --with-gtk=3.0
  _build gtk2 --disable-gtk-doc --disable-webkit2 --with-gtk=2.0
}

package_webkitgtk2() {
  pkgdesc+=" for GTK2"
  depends+=(${MINGW_PACKAGE_PREFIX}-gtk2)
  #provides=("${MINGW_PACKAGE_PREFIX}-libwebkit2=${pkgver}")
  cd "${srcdir}/build-gtk2"
  make -j1 DESTDIR="$pkgdir" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}

package_webkitgtk3() {
  depends+=(${MINGW_PACKAGE_PREFIX}-gtk3)
  optdepends+=("${MINGW_PACKAGE_PREFIX}-gtk2: Netscape plugin support")
  #provides=("${MINGW_PACKAGE_PREFIX}-webkitgtk3=${pkgver}" "${MINGW_PACKAGE_PREFIX}-libwebkit3=${pkgver}")
  cd "${srcdir}/build-gtk3"
  make -j1 DESTDIR="$pkgdir" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}

package_mingw-w64-i686-webkitgtk2() {
  package_webkitgtk2
}

package_mingw-w64-i686-webkitgtk3() {
  package_webkitgtk3
}

package_mingw-w64-x86_64-webkitgtk2() {
  package_webkitgtk2
}

package_mingw-w64-x86_64-webkitgtk3() {
  package_webkitgtk3
}

md5sums=('245a9f8cac251662b7abf19903332038'
         '7408cd3f6624076ffb41c7b4364faee5'
         'b353ef80d7cab43524aaf5bf510d1778'
         '15587d5007fabb1700e2ed4a04085c30'
         'fd7ffaa30ddb9146f56a74602bb5ce9d'
         'd09eb8edbf720c331d01a58f65eaa0a6'
         '288b3d33b3a9826fa5dc3ce748ef1b11'
         '29ab03a44da205dcd38156d63dfee22b'
         '8f9b6a0ef1da6a8b26d7e23c2ca03e31'
         '05fe8cc73be6493d8e2269b900d03cfb'
         '49505091057a55fb26cc0a837f472c4a'
         'be25ec74f31e48e9b177e551290ded7f'
         '84190dfb3082e2a46bf924c179f6f02e'
         '2d8c6f57eed675032748dfbbc2e3e022'
         'b3668d854977f02686db56b0036e14bc'
         'e05eca1b6fe088dcef0f72971f8540e1'
         'c8e10c09e64e7ea9e53de01748e35190'
         '166ae22cb089e0861525004ec9eb9820'
         '054075647ddf38b5e2b2f8226a5043f0'
         '1f1901b881d992261cf97e1c14939667'
         'ab2a01c8c34bdec57a6b4fa71d9ccdaf'
         '84417e71df0b4ebe919ef89cdeedd380'
         '78e8c4c15f52ebf42f0aa66fe28acc22'
         '615feb1233082dadc2f63faa01ce778f'
         '292b9380c711202a166c05d84af61fa7'
         '290c2221a0caebe24650f09e08a9f4dd'
         '9dfc2658031dbc73606495450690e08d')
